package cnsatmsmart.automation.mmi.controller.Buffer;

/**
 * Merupakan kelas yang berisi data asterix21
 * @author SIK - PTIK, BPPT
 */
public class Asterix21Data
{
    /* Atribut-atribut yang dimiliki oleh kelas Asterix21Data */
        private short Catalog, Length1, Length2;
        private short[] ArrData = new short[2048];
        private int BufferLen;
        private short[] DataBuffer = new short[2048];

    /* Constructor - user defined constructor, no default constructor */
        /**
         * Konstruktor
         * @param cat Catalog
         * @param length1 Octet High
         * @param length2 Octet Low
         * @param arrdata Array of asterix data
         * @param bufferLen Panjang dari array data
         */
        public Asterix21Data(short cat, short length1, short length2, short[] arrdata, int bufferLen)
        {
            this.Catalog = cat;
            this.Length1 = length1;
            this.Length2 = length2;
            System.arraycopy(arrdata, 0, ArrData, 0, 2048);
            this.BufferLen = bufferLen;

            FillDataBuffer();
        }

    /**
     * Prosedur untuk mengisi data buffer dengan urutan catalog, octet high, octet low, dan isi dari array data
     */
    private void FillDataBuffer()
    {
        int i = 0;
        int j = 0;
        this.DataBuffer[i++] = Catalog;
        this.DataBuffer[i++] = Length1;
        this.DataBuffer[i++] = Length2;

        while (i < BufferLen)
        {
            this.DataBuffer[i++] = ArrData[j++];
        }
    }

    /**
     * Copy Constructor
     * @param another Objek Asterix21Data yang ingin dicopy
     */
    public Asterix21Data(Asterix21Data another){
        this (another.getCatalog(), another.getLength1(), another.getLength2(), another.getArrData(), another.getBufferLen());
    }

    /* Getter */
    /**
     * Mengembalikan katalog
     * @return Catalog
     */
    public short getCatalog()
        {
            return Catalog;
        }

        /**
         * Mengembalikan Octet High
         * @return Octet High
         */
        public short getLength1()
        {
            return Length1;
        }

        /**
         * Mengembalikan Octet Low
         * @return Octet Low
         */
        public short getLength2()
        {
            return Length2;
        }

        /**
         * Mengembalikan Array Data Asterix
         * @return Array Data Asterix
         */
        public short[] getArrData()
        {
            return ArrData;
        }

        /**
         * Mengembalikan panjang array data
         * @return Panjang array data
         */
        public int getBufferLen()
        {
            return BufferLen;
        }

        /**
         * Mengembalikan Data Buffer
         * @return Data Buffer
         */
        public short[] getDataBuffer()
        {
            return DataBuffer;
        }
}
